const AbstractController = require('./abstract.controller');
const userService = require('../services/user.service');


class UserController extends AbstractController {
    constructor() {
        super()
    }
    async login(ctx) {
        let name = ctx.getParameter('name'),
            password = ctx.getParameter('password'),
            token = ctx.getParameter('token'),
            captcha = ctx.getParameter('captcha');
        let result = await userService.login({ name, password, token, captcha });
        ctx.session.user = { name: "dangdang" };
        ctx.body = result instanceof Boolean ? this.success('登录成功') : this.error(result);
    }
    async getSession(ctx) {
        let data = ctx.session.count || 0;
        ctx.session.count = ++data;
        ctx.body = this.success(data);
    }
}

module.exports = global.buildClass(UserController);

